package pdfsetter.ui;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

/**
 * This command is responsible for group all paths to input files and form from them list of files.
 * 
 * @author Andrzej Dorobisz
 */
public class FilesCommand implements PartCommand {
    private String[] args;
    private boolean initialized;

    public FilesCommand() {
        this.initialized = false;
    }

    @Override
    public String getName() {
        return "-files";
    }

    @Override
    public void printUsage(String indent) {
        System.out.println(indent + "-files file1.pdf [file2.pdf file3.pdf ...]");
    }

    @Override
    public boolean setArgs(String[] args) {
        if ((args == null) || (args.length == 0))
            return false;
        this.args = args;
        initialized = true;
        return true;
    }

    @Override
    public boolean isInitialized() {
        return initialized;
    }

    @Override
    public List<File> process() throws ProcessCommandException {
        List<File> fileList = new LinkedList<File>();
        for (String path : args) {
            fileList.add(new File(path));
        }
        return fileList;
    }
}
